﻿using System;
using System.IO;
using Windows.Storage;

namespace DNFImagePacks2Manager.Helpers
{
    // 文件工具
    public sealed class FileHelper
    {
        // APP路径
        private readonly static string appFolder = ApplicationData.Current.LocalFolder.Path;

        // 获取APP路径
        public static string GetAppFolder => Path.Combine(appFolder);

        // 文件是否存在
        public static bool ExistFile(string path, string filename)
        {
            string file = Path.Combine(path, filename);
            return File.Exists(file);
        }

        // 重命名文件
        public static bool RenameFile(string path, string filename, string newName)
        {
            try
            {
                string file = Path.Combine(path, filename);
                string newFile = Path.Combine(path, newName);
                if (File.Exists(newFile))
                {
                    return false;
                }
                if (File.Exists(file))
                {
                    File.Move(file, newFile);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        // 删除文件
        public static bool DeleteFile(string path, string filename)
        {
            string file = Path.Combine(path, filename);
            try
            {
                if (File.Exists(file))
                {
                    File.Delete(file);
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
